<template>
  <view class="home">
    <theHeader :username="realname" />
    <view class="wrap">
      <u-swiper
        :list="list"
        height="320"
        indicator-pos="bottomRight"
        :title="true"
      ></u-swiper>
    </view>
    <view class="menu_title">系统入口</view>
    <view class="menu_list">
      <view
        class="list"
        v-for="(item, index) in menuList"
        :key="index"
        @click="jump(item.path, item.type)"
      >
        <image :src="item.imageSrc" mode="" />
        <view>{{ item.title }}</view>
      </view>
    </view>
    <u-toast ref="uToast" />
  </view>
</template>

<script>
import theHeader from "../../components/header/header";
import { login } from "@/request/common.js";
import { getChildsystem } from "../../request/login";
import { getSaveuser } from "../../request/dcxt";
export default {
  data() {
    return {
      realname: "",
      userid: "",
      list: [
        {
          image: "../../static/image/lunbo/image1.png",
          title: "",
        },
        {
          image: "../../static/image/lunbo/image2.png",
          title: "",
        },
        {
          image: "../../static/image/lunbo/image3.png",
          title: "",
        },
      ],
      menuList: [
        {
          title: "督查管理",
          imageSrc: "../../static/image/home/ducha.png",
          path: "/pages/dcxt/index",
          type: "sys_ducha",
        },
        {
          title: "重大项目",
          imageSrc: "../../static/image/home/zhongda.png",
          path: "/pages/zdxm/index",
          type: "sys_zhongda",
        },
        {
          title: "绩效管理",
          imageSrc: "../../static/image/home/jixiao.png",
          type: "sys_jixiao",
        },
        {
          title: "经济指标",
          imageSrc: "../../static/image/home/jingji.png",
          type: "sys_jingji",
        },
        {
          title: "招商引资",
          imageSrc: "../../static/image/home/zhaoshang.png",
          type: "sys_zhaoshang",
        },
      ],
    };
  },
  components: {
    theHeader,
  },
  onShow() {
    this.realname = uni.getStorageSync("realname");
    this.userid = uni.getStorageSync("user_id");
  },
  methods: {
    jump(path, type) {
      if (path == "/pages/zdxm/index") {
        this.jumpZD();
      } else {
        var params = {
          userCode: this.userid,
          userSysCode: type,
        };
        getChildsystem(params).then((res) => {
          console.log("111111111111111");
          console.log(res.data.result);
          var result = res.data.result;
          if (result.length == 1) {
            uni.setStorageSync("roleId", result[0].roleId);
            uni.setStorageSync("loginId", result[0].userId);
            uni.setStorageSync("userType", result[0].userType);
            getSaveuser({
              userId: result[0].userId,
            }).then((res) => {});
            uni.navigateTo({
              url: path + "?username=" + result[0].username,
            });
          } else if (result.length > 1) {
            uni.navigateTo({
              url:
                "/pages/xzjs/index?info=" +
                JSON.stringify(result) +
                "&path=" +
                path +
                "&type=" +
                type
            });
          } else {
            this.$refs.uToast.show({
              title: "当前账号未获得该系统访问权限!",
              type: "error",
              duration: 2000,
            });
          }
        });
      }
    },
    jumpZD() {
      login({
        phone: uni.getStorageSync("userphone"),
      }).then((res) => {
        var token = res.data.result.token;
        var role = res.data.result.role;
        // console.log('获取token',token)
        this.$store.commit("TOKEN", token);
        uni.setStorageSync("token", token);
        this.$store.commit("ROLE", role);
        uni.setStorageSync("role", role);
        uni.navigateTo({
          url: "/pages/zdxm/index",
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  min-height: 100vh;
  background-color: #f6f7fa;

  .wrap {
    width: 710rpx;
    height: 320rpx;
    margin: 0 auto;
    margin-top: -150rpx;
  }

  .menu_title {
    margin: 23rpx 0 23rpx 20rpx;
    font-size: 32rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #272b32;
  }

  .menu_list {
    width: 710rpx;
    margin: 0 auto;
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-start;
    background-color: #ffffff;
    border-radius: 8rpx;
    padding: 20rpx 0;

    .list {
      width: 236rpx;
      height: 223rpx;

      image {
        display: block;
        width: 120rpx;
        height: 120rpx;
        margin: 0 auto;
        margin-top: 20rpx;
      }

      view {
        font-size: 28rpx;
        font-family: PingFang SC;
        font-weight: bold;
        color: #272b32;
        margin-top: 16rpx;
        text-align: center;
      }
    }
  }
}
</style>
